//
//  CYOrderCell.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/10/16.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYOrderCell.h"
@interface CYOrderCell ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation CYOrderCell
- (instancetype)init{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.backgroundColor = THEME_COLOR;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.mj_header = [CYRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshDown)];//下拉刷新
        _tableView.mj_footer = [CYRefreshFooder footerWithRefreshingTarget:self refreshingAction:@selector(refreshUp)];//上拉加载
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(0.0,0.0,0.0,0.0));
        }];
    }
    return _tableView;
}
- (void)setModel:(CYTotalOrderModel *)model{
    if (_model != model) {
        if (_model.bets_data.count < 1)
            _model = model;
        else if(_model.bets_data.count/_rows < model.total_page && _page > 1 && model.bets_data.count > 0)
            [_model.bets_data addObjectsFromArray:model.bets_data];
        else if (_page == 1 && model.bets_data.count > 0)
            [_model.bets_data replaceObjectsInRange:NSMakeRange(0, MIN(_rows, model.bets_data.count)) withObjectsFromArray:model.bets_data];
        [_tableView reloadData];
    }
}

- (void)refreshDown{
    
    
}

- (void)refreshUp{
    
    
}
#pragma - mark - UITableViewDataSource method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _model.bets_data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifier = @"CYOrderCell";
    CYOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
        cell = [[CYOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    CYOrderModel *subOrderModel = _model.bets_data[indexPath.row];
    cell.name = subOrderModel.cz_name;//彩种名字
    cell.date = subOrderModel.action_no;//彩种日期
    cell.bet_way = subOrderModel.wf_name;//投注方式
    cell.bet_money = subOrderModel.bet_bonus;//投注金额
    cell.status = subOrderModel.zhuangtai;//注单状态
    cell.money = subOrderModel.bonus;//中奖金额
    return cell;
    
}
#pragma - mark - UITableViewDelegate method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ROWHEIGHT;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    CYOrderDetailViewController *detailVC = [[CYOrderDetailViewController alloc]init];
    //    CYOrderModel *subOrderModel  = _model.bets_data[indexPath.row];
    //    detailVC.bet_id = subOrderModel.ID;
    //    [self.navigationController pushViewController:detailVC animated:YES];
}
@end
